package com.ndp.fb.rdb.db.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.rdb.api.ConnectionObjectAdwordsRdbService;
import com.ndp.fb.rdb.db.DaoTemplate;
import com.ndp.fb.rdb.db.impl.mapper.DefaultRowMapper;
import com.ndp.fb.rdb.model.adword.ConnectionObjectAdwords;

import java.util.List;

/**
 * Created by sisi.chen on 2015/9/24.
 */
@Service
public class ConnectionObjectAdwordsRdbServiceImpl extends DaoTemplate implements ConnectionObjectAdwordsRdbService{

    @Override
    public List<ConnectionObjectAdwords> findByFbConnectionObjectIdAndAdwordId(Long fbConnectionObjectId, Long adwordId) {
        String sql = "select * from connection_object_adwords where fb_connection_object_id = ? and adword_id = ?";
        return getJdbcTemplate().query(sql, new Object[]{fbConnectionObjectId, adwordId}, DefaultRowMapper.autoRowMapper(ConnectionObjectAdwords.class));
    }

    @Override
    public void save(final Long fbConnectionObjectId, final Long adwordId) {

        ConnectionObjectAdwords connectionObjectAdwords=new ConnectionObjectAdwords();
        connectionObjectAdwords.setAdwordId(adwordId);
        connectionObjectAdwords.setFbConnectionObjectId(fbConnectionObjectId);
        saveResultId(connectionObjectAdwords);
    }

    @Override
    public void deleteByAdwordId(Long adwordId) {
        String sql = "delete from connection_object_adwords where adword_id= " + adwordId;
        executeSql(sql);
    }
}
